<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class RegisterController extends Controller
{
    //渲染注册页面
    public function index()
    {
        return view('register/register');
    }
    //用户注册逻辑
    public function register()
    {
        $this->validate(request(),[
            'name' => 'required|unique:users,name|max:10|min:2',
            'password'=>'required|min:6',
        ]);
        $name = request('name');
        $password = bcrypt(request('password'));
        $user = User::create(compact('name','password'));
        return redirect('/login');
    }
}
